//
//  FengShuiLuoPan.m
//  Fengshui
//
//  Created by huliang on 13-6-4.
//
//

#import "FengShuiLuoPan.h"

@interface FengShuiLuoPan ()

@end

@implementation FengShuiLuoPan

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.locationManager= [[CLLocationManager alloc]init];
    _locationManager.delegate = self;
    if ([CLLocationManager headingAvailable]) {
        //设置精度
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        //设置滤波器不工作
        self.locationManager.headingFilter = kCLHeadingFilterNone;
        //开始更新
        [self.locationManager startUpdatingHeading];
    }
}

#pragma mark - 更新朝向信息
-(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
    //每次要重置view的位置，才能保证图片每次偏转量正常，而不是叠加，指针方向正确。
    self.luopanImgView.transform = CGAffineTransformIdentity;
    CGAffineTransform transform = CGAffineTransformMakeRotation(-1 * M_PI*newHeading.magneticHeading/180.0);

    //    CGAffineTransform transform = CGAffineTransformMakeTranslation(10, 50);
    self.luopanImgView.transform = transform;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

-(void)dealloc{
    [super dealloc];
    self.locationManager = nil;
}

@end
